public class TeemoAttacking {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        int count = 0;
        for(int i = 1; i < n; i++) {
            int x = timeSeries[i] - timeSeries[i-1];
            if(x >= duration) {
                count += duration;
            }else {
                count += x;
            }
        }
        // 上面for循环没有统计最后一次攻击的中毒时间
        // 最后一次攻击中毒必持续 duration 秒, 因此在结果上 += duration 秒即可
        return count += duration;
    }
}
